package com.ka.dialog;

import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.ka.lifemanagement.R;

public class MoneyDialog extends DialogFragment {

	protected View contentView;
	protected Button enter_money_ok;
	public AddMoneyEvent delegate;
	protected EditText enter_money_value;

	public interface AddMoneyEvent {
		public void okEvent(String val);

		public void cancelEvent();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		getDialog().setTitle("Nhập số tiền");
		contentView = inflater.inflate(R.layout.dialog_custom_money, container,
				false);

		return contentView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);

		initial();
		execution();

	}

	private void initial() {
		enter_money_ok = (Button) contentView.findViewById(R.id.enter_money_ok);
		enter_money_value = (EditText) contentView
				.findViewById(R.id.enter_money_value);
	}

	private void execution() {
		enter_money_ok.setOnClickListener(okEvent);
	}

	@Override
	public void onCancel(DialogInterface dialog) {
		super.onCancel(dialog);
		delegate.cancelEvent();

	}

	OnClickListener okEvent = new OnClickListener() {

		@Override
		public void onClick(View v) {
			delegate.okEvent(enter_money_value.getText().toString().trim());
		}
	};

}
